Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@types/node-forge
Advanced tools
@types/node-forge provides TypeScript type definitions for the node-forge library, which is a native implementation of TLS (and various other cryptographic tools) in JavaScript. It allows developers to perform a variety of cryptographic operations such as encryption, decryption, hashing, and digital signatures.
Encryption and Decryption
This feature allows you to encrypt and decrypt data using the AES-CBC algorithm. The code sample demonstrates how to encrypt a simple 'Hello World' string and then decrypt it back to its original form.
const forge = require('node-forge');
const key = forge.random.getBytesSync(16);
const iv = forge.random.getBytesSync(16);
const cipher = forge.cipher.createCipher('AES-CBC', key);
cipher.start({iv: iv});
cipher.update(forge.util.createBuffer('Hello World'));
cipher.finish();
const encrypted = cipher.output;
const decipher = forge.cipher.createDecipher('AES-CBC', key);
decipher.start({iv: iv});
decipher.update(encrypted);
decipher.finish();
const decrypted = decipher.output.toString();
console.log(decrypted);
Hashing
This feature allows you to create cryptographic hashes using various algorithms like SHA-256. The code sample demonstrates how to hash a 'Hello World' string using SHA-256.
const forge = require('node-forge');
const md = forge.md.sha256.create();
md.update('Hello World', 'utf8');
const hash = md.digest().toHex();
console.log(hash);
Digital Signatures
This feature allows you to create and verify digital signatures. The code sample demonstrates how to sign a 'Hello World' string with a private key and then verify the signature with the corresponding public key.
const forge = require('node-forge');
const pki = forge.pki;
const keys = pki.rsa.generateKeyPair(2048);
const md = forge.md.sha256.create();
md.update('Hello World', 'utf8');
const signature = keys.privateKey.sign(md);
const verified = keys.publicKey.verify(md.digest().bytes(), signature);
console.log(verified);
TLS/SSL
This feature allows you to create and manage TLS/SSL certificates. The code sample demonstrates how to generate a self-signed certificate.
const forge = require('node-forge');
const pki = forge.pki;
const keys = pki.rsa.generateKeyPair(2048);
const cert = pki.createCertificate();
cert.publicKey = keys.publicKey;
cert.serialNumber = '01';
cert.validity.notBefore = new Date();
cert.validity.notAfter = new Date();
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
const attrs = [{name: 'commonName', value: 'example.org'}];
cert.setSubject(attrs);
cert.setIssuer(attrs);
cert.sign(keys.privateKey);
const pem = pki.certificateToPem(cert);
console.log(pem);
crypto-js is a popular library for cryptographic algorithms implemented in JavaScript. It provides a wide range of cryptographic functions including encryption, decryption, hashing, and HMAC. Compared to node-forge, crypto-js is more focused on providing a simple API for common cryptographic tasks and is often used in browser environments.
jose is a library for JavaScript Object Signing and Encryption (JOSE) standards, including JSON Web Tokens (JWT), JSON Web Encryption (JWE), and JSON Web Signatures (JWS). It is more specialized compared to node-forge, focusing on the JOSE standards and providing a high-level API for working with JWTs and related technologies.
openpgp is a JavaScript implementation of the OpenPGP standard for encryption and signing of data. It is specifically designed for working with PGP keys and messages. Compared to node-forge, openpgp is more specialized for PGP-related tasks and provides a higher-level API for working with PGP keys and encrypted messages.
npm install --save @types/node-forge
This package contains type definitions for node-forge (https://github.com/digitalbazaar/forge).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node-forge
Additional Details
These definitions were written by Seth Westphal https://github.com/westy92, Kay Schecker https://github.com/flynetworks, Aakash Goenka https://github.com/a-k-g, Rafal2228 https://github.com/rafal2228, Beeno Tung https://github.com/beenotung, Joe Flateau https://github.com/joeflateau, Nikita Koryabkin https://github.com/Apologiz, timhwang21 https://github.com/timhwang21, supaiku0 https://github.com/supaiku0, Anders Kaseorg https://github.com/andersk, and Sascha Zarhuber https://github.com/saschazar21.
FAQs
TypeScript definitions for node-forge
The npm package @types/node-forge receives a total of 5,627,367 weekly downloads. As such, @types/node-forge popularity was classified as popular.
We found that @types/node-forge demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.